package Chapter5;
class Ticket1 implements Runnable{
	private int tickets=10;
	Object lock=new Object();
	public void run() {
		while(true) {
			synchronized(lock) {
				try {
					Thread.sleep(10);
				}catch(InterruptedException e) {
					e.printStackTrace();
				}
				if(tickets>0) {
					System.out.println(Thread.currentThread().getName()+"---saled "+tickets--);
				}else {
					break;
				}
			}
		}
	}
}

public class Example12 {
	public static void main(String[] args) {
		Ticket1 ticket=new Ticket1();
		new Thread(ticket,"thread1").start();
		new Thread(ticket,"thread2").start();
		new Thread(ticket,"thread3").start();
		new Thread(ticket,"thread4").start();
	}

}
